Make the `DependencyInner::specified_req` field a bool.
authorJohn Ericson <Ericson2314@Yahoo.com>
Tue, 12 Jul 2016 16:55:02 +0000 (09:55 -0700)
committerJohn Ericson <Ericson2314@Yahoo.com>
Tue, 12 Jul 2016 16:55:02 +0000 (09:55 -0700)
This field is hardly used. I could almost get rid if it completely, but
then the dependency verifier would have to abort on, say, no version req
specified or the any req. Crates.io indeed doesn't want such wildcards, but
other registries some day may have a different policy.

Making it a mere bool---since all the information it contained is in the
`req` field anyways---was the next best thing.

src/cargo/core/dependency.rs
src/cargo/ops/registry.rs

index a030de626f9da2759a18caf0b4c9139b881602d7..08966e6e4382072662c0c2f846485a96c82ca6a5 100644 (file)
@@ -21,7 +21,7 @@ pub struct DependencyInner {
     name: String,
     source_id: SourceId,
     req: VersionReq,
-    specified_req: Option<String>,
+    specified_req: bool,
     kind: Kind,
     only_match_name: bool,
 
@@ -90,15 +90,15 @@ impl DependencyInner {
     pub fn parse(name: &str,
                  version: Option<&str>,
                  source_id: &SourceId) -> CargoResult<DependencyInner> {
-        let version_req = match version {
-            Some(v) => try!(VersionReq::parse(v)),
-            None => VersionReq::any()
+        let (specified_req, version_req) = match version {
+            Some(v) => (true, try!(VersionReq::parse(v))),
+            None => (false, VersionReq::any())
         };
 
         Ok(DependencyInner {
             only_match_name: false,
             req: version_req,
-            specified_req: version.map(|s| s.to_string()),
+            specified_req: specified_req,
             .. DependencyInner::new_override(name, source_id)
         })
     }
@@ -113,7 +113,7 @@ impl DependencyInner {
             optional: false,
             features: Vec::new(),
             default_features: true,
-            specified_req: None,
+            specified_req: false,
             platform: None,
         }
     }
@@ -122,9 +122,7 @@ impl DependencyInner {
     pub fn name(&self) -> &str { &self.name }
     pub fn source_id(&self) -> &SourceId { &self.source_id }
     pub fn kind(&self) -> Kind { self.kind }
-    pub fn specified_req(&self) -> Option<&str> {
-        self.specified_req.as_ref().map(|s| &s[..])
-    }
+    pub fn specified_req(&self) -> bool { self.specified_req }
 
     /// If none, this dependency must be built for all platforms.
     /// If some, it must only be built for matching platforms.
@@ -234,7 +232,7 @@ impl Dependency {
     pub fn name(&self) -> &str { self.inner.name() }
     pub fn source_id(&self) -> &SourceId { self.inner.source_id() }
     pub fn kind(&self) -> Kind { self.inner.kind() }
-    pub fn specified_req(&self) -> Option<&str> { self.inner.specified_req() }
+    pub fn specified_req(&self) -> bool { self.inner.specified_req() }
 
     /// If none, this dependencies must be built for all platforms.
     /// If some, it must only be built for the specified platform.
index 29d54f2b499730a1bf87f222cd96dcb6b70338c7..a076f01d4d1fd5ccc970e5d28f3982bd63b5a859 100644 (file)
@@ -71,7 +71,7 @@ fn verify_dependencies(pkg: &Package, registry_src: &SourceId)
                        -> CargoResult<()> {
     for dep in pkg.dependencies().iter() {
         if dep.source_id().is_path() {
-            if dep.specified_req().is_none() {
+            if !dep.specified_req() {
                 bail!("all path dependencies must have a version specified \
                        when publishing.\ndependency `{}` does not specify \
                        a version", dep.name())